function sum_amount()
{
        var total_amount = 0;
        var invoice_list = document.getElementsByName("invoice_id");
        for(i=0;i<invoice_list.length;i++)
        {
                if(invoice_list[i].checked == true)
                {
                        total_amount += Math.round(parseFloat(document.getElementById('invoice_'+invoice_list[i].value).value)*100)/100;
                }
        }
        document.getElementById("amount").value = Math.round(total_amount*100)/100;
}
function show_invoice_list()
{
		var customer_id_selected = document.getElementById("customer").value;
		{% for iv in invoice_list %}
				var invoice = document.getElementById("cust_{{iv['id']}}_{{iv['customer_id']}}");				
				//var customer_list = document.getElementsByName("cust_{{iv['id']}}_{{iv['customer_id']}}");	
				//if(navigator.userAgent.indexOf("MSIE")>=0||navigator.userAgent.indexOf("Opera")>=0){
				//		customer_list = getElementsByName_ie('dl',"cust_{{iv['customer_id']}}");
				//}
				if(document.getElementById("invoice_{{iv['customer_id']}}_{{iv['id']}}")!=null){
						document.getElementById("invoice_{{iv['customer_id']}}_{{iv['id']}}").checked = false;
				}
				invoice.style.display='none';
				//for(i=0;i<customer_list.length;i++)
				//{
				//		customer_list[i].style.display="none";
				//}
		{% endfor %}
		document.getElementById("checkall").checked = false;
		document.getElementById("check_all").style.display = "none";
		if(customer_id_selected != ""){
				{% for iv in invoice_list %}
					if({{iv['customer_id']}} == parseInt(customer_id_selected)){
							var invoice = document.getElementById("cust_{{iv['id']}}_"+customer_id_selected);
							invoice.style.display="";
					}
				//var customer_list = document.getElementsByName('cust_'+customer_id_selected);
				//if(navigator.userAgent.indexOf("MSIE")>=0||navigator.userAgent.indexOf("Opera")>=0){
				//		customer_list = getElementsByName_ie('dl','cust_'+customer_id_selected);						
				//}				
				//for(i=0;i<customer_list.length;i++)
				//{
				//		customer_list[i].style.display="";
				//}
				{% endfor %}
				document.getElementById("check_all").style.display = "";				
		}
		sum_amount();
}
function check_all()
{
		var customer_id_selected = document.getElementById("customer").value;
		if(customer_id_selected!=''){
				{% for iv in invoice_list %}
						if(document.getElementById('invoice_'+customer_id_selected+"_{{iv['id']}}")!=null)
						{
								document.getElementById('invoice_'+customer_id_selected+"_{{iv['id']}}").checked = document.getElementById("checkall").checked;
						}
				{% endfor %}
		}
		{% for cu in customers %}
				//var custlist = document.getElementsByName("cust_{{cu['id']}}");
				//if(navigator.userAgent.indexOf("MSIE")>=0||navigator.userAgent.indexOf("Opera")>=0){
				//		custlist = getElementsByName_ie('dl',"cust_{{cu['id']}}");
				//}
				//if(custlist[0] && custlist[0].style.display != "none")
				//{
				//		{% for iv in invoice_list %}
				//				if(document.getElementById("{{cu['id']}}_{{iv['id']}}")!=null)
				//				{
				//						document.getElementById("{{cu['id']}}_{{iv['id']}}").checked = document.getElementById("checkall").checked;
				//				}
				//		{% endfor %}
				//}
		{% endfor %}
		sum_amount();
}
